<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('loan_tag', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->default(0)->comment("用户id");
            $table->char('org_root',3)->nullable()->comment('顶级机构');
            $table->char('org_code',11)->nullable()->comment('所属机构');
            $table->unsignedTinyInteger('share_for_sub')->default(0)->comment("子机构是否可用");
            $table->string('title', 40)->comment("标题");
            $table->timestamps();
        });
        DB::statement("ALTER TABLE `loan_tag` COMMENT='标签'");

        Schema::create('loan_application_tag', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tag_id')->default(0)->comment("标签id");
            $table->unsignedBigInteger('loan_id')->default(0)->comment("申请物料id");
            $table->index('loan_id');
            $table->index('tag_id');
        });
        DB::statement("ALTER TABLE `loan_application_tag` COMMENT='贷款标签'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('loan_tag');
        Schema::dropIfExists('loan_application_tag');
    }
};
